package  com.zzkj.control
{
	import com.firemoss.modelglue.event.ModelGlueEvent;
	import com.storage.model.AppModelLocator;
	import com.storage.view.widgets.ConfirmWin;
	import com.storage.view.widgets.form.ZZEditForm;
	import com.storage.view.widgets.grid.ZZGrid;
	import com.storage.vo.query.QueryInfoVO;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.controls.DataGrid;
	import mx.managers.PopUpManager;
	
	public class AutoCreateGrid
	{
		public function AutoCreateGrid()
		{
		}
		
		
		//public static var g:ZZGrid;
	
		//通用的查找函数
		public static function searchHandler(query:QueryInfoVO,name:String,grid:DataGrid):void{
			var e:ModelGlueEvent = new ModelGlueEvent("doCommonSearch");
			e.setValue("name",name);
			e.setValue("query",query);
			if(grid!=null){
				e.setValue("grid",grid);	
			}
			e.dispatch();
		}
		
		//load all
		public static function loadAllForComboBox(query:QueryInfoVO,name:String,grid:ZZGrid):void{
			var e:ModelGlueEvent = new ModelGlueEvent("loadAllForComboBox");
			e.setValue("name",name);
			e.setValue("query",query);
			e.setValue("zzgrid",grid);
			e.dispatch();
			
		}
	
		//通用的添加函数
		public static function addObjectFunction(s:Number,picvo:Class,f:ZZEditForm,grid:ZZGrid):void{
			//if(f.bindObject==null)
			f.bindObject = new picvo();
			f.bindObject.rowStatus = s;
			f.comboBoxDataDic = grid.comboBoxDataDic;
			grid.dispatchEvent(new Event(Event.CHANGE));
		}
		public static function deleteObjectFunction(msg:String,g:DisplayObject,delFn:Function):void{
			var cw:ConfirmWin = new ConfirmWin();
					cw.message =msg;
								
					PopUpManager.addPopUp(cw,g,true);
					PopUpManager.centerPopUp(cw);
					cw.closeF = function():void{
						PopUpManager.removePopUp(cw);
					}
					cw.confirmF = function():void{
						delFn();
					}
		}
		
		public static function deleteChildObjectFunction():void{
			
		}
		//通用的传值函数
		public static function sendBindObject(list:Array,
						fName:String,clazz:Class,f:ZZEditForm,grid:ZZGrid):void{
			f.firstControlName = fName;
			if(list.length>0 && list.length===1){
				f.bindObject = list[0] as clazz;
				f.bindObject.rowStatus = 16;
			}
			else if(list.length>1)
				f.objectList = list;
			else
				f.bindObject = new clazz();
			if(grid.childZZGrid!=null){
				grid.childZZGrid.dataGrid.dataProvider =  f.bindObject[grid.childGridEntityName] as ArrayCollection;	
				//grid.childZZGrid..refresh();
				//grid.childZZGrid.dataGrid.dataProvider = grid.childZZGrid.dateGridList;	
			}
			f.comboBoxDataDic = grid.comboBoxDataDic;
			
			grid.dispatchEvent(new Event(Event.CHANGE));
		}
		

	}
}